import { useState } from "react"

function MyComponents() {
  const [car,setcar]=useState({year:2020,make:'hhdj',color:'red'})
  function ChangeYear(e){
    // setcar({...car,year:e.target.value})
    setcar(c=>({...c,year:e.target.value}))
  }
  function ChangeMake(e){
    setcar(c=>({...c,make:e.target.value}))
  }
  function ChangeColor(e){
    setcar(c=>({...c,color:e.target.value}))
  }
  return(
    <div>
      <p>Car is {car.year}{car.make},{car.color}</p>
      <input type="number" value={car.year} onChange={ChangeYear}/><br />
      <input type="text"  value={car.make} onChange={ChangeMake}/><br />
      <input type="text" value={car.color} onChange={ChangeColor}/><br />
    </div>
  )
}
export default MyComponents